<?
include_once("_common.php");
@include_once("$g4[path]/lib/mw.builder.lib.php");
include_once("$mw_cash[path]/cybercash.lib.php");

if (!is_numeric($page)) $page = 1;

$sql_common = " from $mw_cash[cash_list_table] ";
$sql_search = " where mb_id = '$member[mb_id]' and cl_status = '1' and cl_cash < 0 ";
$sql_order = " order by cl_datetime desc ";

if ($rel_table) {
    $sql_search .= " and rel_table = '$rel_table' ";
    $board = sql_fetch("select * from $g4[board_table] where bo_table = '$rel_table'");
    if (!$board)
	alert("존재하지 않는 게시판입니다.");
}

$sql = "select count(*) as cnt
        $sql_common
        $sql_search";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함  */

$sql = "select *
        $sql_common
        $sql_search
        $sql_order
        limit $from_record, $rows ";
$qry = sql_query($sql);


$list = array();
for ($i=0; $row=sql_fetch_array($qry); $i++) {
    $list[$i] = $row;
    $list[$i][num] = $total_count - ($page - 1) * $rows - $i;
    $list[$i][cl_datetime] = date("Y-m-d", strtotime($list[$i][cl_datetime]));
    $row2 = sql_fetch("select * from $g4[write_prefix]$row[rel_table] where wr_id = '$row[rel_id]'", false);
    $list[$i][title] = cut_str(get_text($row2[wr_subject]), 30);
}

$list_count = count($list);

$write_pages = get_paging($rows, $page, $total_page, "$PHP_SELF?{$qstr}&page=");

$colspan = 5;

$g4[title] = "$board[bo_subject] 구입내역";
include_once("_head.php");
?>
<link rel="stylesheet" href="style.css" type="text/css"/>

<h3 class=title>● <?=$g4[title]?></h3>


<div style="height:20px; margin:10px 0 5px 0;">
    <div style="float:left; color:#888;"> 나의 <?=$mw_cash[cf_cash_name]?> :  <?=number_format($mw_cash[mb_cash])?> <?=$mw_cash[cf_cash_unit]?> </div>
    <div style="float:right; color:#888;"> 전체 <?=number_format($list_count)?> 건 </div>
</div>
<table border=0 cellpadding=0 cellspacing=0 width=100% class=data>
<colgroup width="50"/>
<colgroup width="100"/>
<colgroup width="100"/>
<colgroup width="200"/>
<colgroup width=""/>
<tr>
    <td class="head"> 번호 </td>
    <td class="head"> 날짜 </td>
    <td class="head"> <?=$mw_cash[cf_cash_name]?> </td>
    <td class="head"> 컨텐츠이름 </td>
    <td class="head"> 사용도메인 </td>
</tr>

<? for ($i=0; $i<$list_count; $i++) { ?>
<tr>
    <td class="body"> <?=$list[$i][num]?> </td>
    <td class="body"> <?=$list[$i][cl_datetime]?> </td>
    <td class="body right"> <?=number_format($list[$i][cl_cash])?> <?=$mw_cash[cf_cash_unit]?> </td>
    <td class="body"> <a href="<?=$g4[bbs_path]?>/board.php?bo_table=<?=$list[$i][rel_table]?>&wr_id=<?=$list[$i][rel_id]?>"><?=$list[$i][title]?></a> </td>
    <td class="body left"> <?=$list[$i][cl_domain]?>&nbsp; </td>
</tr>
<? } ?>
<? if ($i==0) echo "<tr><td colspan=$colspan class=none>자료가 없습니다.</td></tr>"; ?>
</table>


<div class="paging"><?=$write_pages?></div>


<?
include_once("_tail.php");
?>
